import 'package:flutter/widgets.dart';
import 'package:mobile_app.core/core/presentation/theme/theme.dart';
import 'package:mobile_app.core/core/presentation/widgets/platform_divider.dart';
import 'package:mobile_app.core/core/presentation/widgets/tiles/tile_rounder.dart';

class RoundedTileGroup extends StatelessWidget {
  RoundedTileGroup({
    required this.tiles,
    this.header,
    this.footer,
    super.key,
  }) : assert(tiles.isNotEmpty);

  final List<Widget> tiles;
  final Widget? header;
  final Widget? footer;

  @override
  Widget build(BuildContext context) {
    final dividedTiles = <Widget>[
      tiles.first,
    ];

    for (var i = 1; i < tiles.length; i++) {
      dividedTiles.add(const PlatformDivider());
      dividedTiles.add(tiles[i]);
    }

    dividedTiles.first = TileTopRounder(
      tile: dividedTiles.first,
    );
    dividedTiles.last = TileBottomRounder(
      tile: dividedTiles.last,
    );

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        if (header != null) header!,
        ...dividedTiles,
        if (footer != null) footer!,
      ],
    );
  }
}

class TileGroupHeader extends StatelessWidget {
  const TileGroupHeader({
    required this.title,
    super.key,
  });

  final String title;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(
        left: 16,
        right: 16,
        bottom: 6,
      ),
      child: Text(
        title.toUpperCase(),
        style: CoreTheme.of(context).textTheme.tileGroupHeader,
        textAlign: TextAlign.start,
      ),
    );
  }
}

class TileGroupFooter extends StatelessWidget {
  const TileGroupFooter({
    required this.title,
    super.key,
  });

  final String title;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(
        left: 16,
        right: 16,
        top: 7.5,
      ),
      child: Text(
        title,
        style: CoreTheme.of(context).textTheme.tileGroupFooter,
        textAlign: TextAlign.start,
      ),
    );
  }
}
